Skip to content

feat(mango): extract mango client#1087

Open
rogaldh wants to merge 23 commits into
solana-foundation:masterfrom
hoodieshq:feat/extract-mango-client
Open

feat(mango): extract mango client#1087
rogaldh wants to merge 23 commits into
solana-foundation:masterfrom
hoodieshq:feat/extract-mango-client

Conversation

@rogaldh

@rogaldh rogaldh commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Description

Removes the Mango v3 instruction decoder and keeps only lightweight detection, so the explorer recognises the (dead) Mango v3 protocol and marks it deprecated without bundling @blockworks-foundation/mango-client / @project-serum/serum. Detection lives in a dedicated @explorer/decoder-mango workspace package.

  • packages/decoder-mango exposes detection only — isMangoInstruction, parseMangoInstructionTitle, resolveMangoInstructionName, getMangoInstructionLabel, MANGO_PROGRAM_IDS, MANGO_V3_PROGRAM_LABEL (plus a /detection subpath). The per-instruction decoders, market lookups, hooks, and their fixtures/tests are gone. With the decoder deleted, the heavy @blockworks-foundation/mango-client is no longer used anywhere and drops out of the lockfile entirely. (@project-serum/serum stays — it's used by the separate Serum decoder, not Mango.)
  • The per-instruction Mango cards and the instruction-program-mango feature slice are removed. Mango v3 instructions now render through a generic CommonInstructionDetailsCard (resolves the program label from the registry, shows raw data), titled e.g. Mango v3 (deprecated): PlacePerpOrder — or No data / Unknown when the payload can't be named.
  • app/utils/programs.ts registers the three Mango v3 program IDs (devnet / testnet / mainnet) with the deprecated label sourced from the package's MANGO_V3_PROGRAM_LABEL — the package is the single source of truth for the addresses + label.
  • Transaction history names Mango v3 instructions from the discriminator via the existing NAME_SOURCES chain (resolveMangoInstructionName) — no payload decoding.

Mango v4 is intentionally out of scope: it's a separate, active Anchor program that resolves its own name/instructions via its on-chain IDL (shown with the existing self-reported indicator), so it needs no bundled decoder or registry entry.

Type of change

  • Bug fix
  • New feature
  • Protocol integration
  • Documentation update
  • Other (please describe):

Refactor + deprecation. Replaces the heavy Mango v3 decoder with detection-only recognition and a deprecation notice. Behaviour change: Mango v3 instructions render a generic deprecated card instead of per-instruction detail cards.

Screenshots

Mango v3 instructions render a single generic card — Mango v3 (deprecated): <name> over the raw instruction data — instead of the previous per-instruction detail cards. No new screens; not a protocol integration.

image image

Testing

  • packages/decoder-mango unit tests cover detection across all instruction variants and edge cases (non-mango program, unknown discriminator, empty/short data) for isMangoInstruction, parseMangoInstructionTitle, resolveMangoInstructionName, and getMangoInstructionLabel.
  • Added Storybook stories for CommonInstructionDetailsCard (named / no-data / unknown), covered by the Vitest story sweep.
  • pnpm lint, pnpm test, and app tsc --noEmit pass locally; the package dist was rebuilt detection-only (no mango-client).

Related Issues

HOO-452

Checklist

  • My code follows the project's style guidelines
  • I have added tests that prove my fix/feature works
  • All checks pass locally (pnpm test, pnpm lint, pnpm typecheck)
  • I have run build:info script to update build information
  • CI/CD checks pass on the PR
  • Screenshots included — required for protocol screens, recommended for other UI changes

Additional Notes

  • Branch rebased onto latest master; pnpm-lock.yaml regenerated — the workspace now includes packages/decoder-mango, and @blockworks-foundation/mango-client is gone entirely (@project-serum/serum remains, used by the Serum decoder).
  • Mango v4 is deliberately not added to the trusted registry — its name stays self-reported via its IDL, with the existing self-reported indicator.

@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

@rogaldh is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
explorer Ready Ready Preview, Comment Jul 1, 2026 9:04pm

Request Review

@greptile-apps

greptile-apps Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces the full Mango v3 per-instruction decoder (and its @blockworks-foundation/mango-client dependency) with a lightweight detection-only package (@explorer/decoder-mango) that identifies Mango v3 instructions and resolves their names from a hardcoded discriminator table. Mango v3 instructions now render a single generic deprecated card (CommonInstructionDetailsCard) instead of the previous per-instruction detail cards.

  • Adds packages/decoder-mango workspace package exposing isMangoInstruction, parseMangoInstructionTitle, resolveMangoInstructionName, getMangoInstructionLabel, MANGO_PROGRAM_IDS, and MANGO_V3_PROGRAM_LABEL — with unit tests covering all edge cases.
  • Registers the three Mango v3 program IDs in PROGRAM_INFO_BY_ID with the deprecated label, and plugs resolveMangoInstructionName into the NAME_SOURCES chain for transaction-history naming.
  • Removes all per-instruction Mango cards, their types, and the MangoDetails dispatcher; the @blockworks-foundation/mango-client dependency is fully dropped from the lockfile.

Confidence Score: 5/5

Safe to merge — the change is a well-scoped removal of a dead decoder with a clean detection-only replacement; no data paths are broken.

All integration points (InstructionsSection, TokenHistoryCard, NAME_SOURCES chain, programs registry) are correctly wired. The discriminator table is pinned by dedicated tests that would catch future accidental shifts. The heavy @blockworks-foundation/mango-client is fully removed and the new workspace package has no production dependencies beyond already-present peer deps.

No files require special attention.

Important Files Changed

Filename Overview
packages/decoder-mango/src/detection.ts New detection module: program-id gating, u32 LE discriminator read, and three exported helpers; all edge cases (short data, unknown discriminator, non-Mango program) handled correctly and tested.
packages/decoder-mango/src/instruction-names.ts Hardcoded 73-entry discriminator→name map (0–73, index 40 intentionally absent); boundary values pinned by tests to catch future accidental edits.
app/features/transaction/ui/CommonInstructionDetailsCard.tsx New generic card for recognized-but-not-decoded programs; uses program registry label + caller-supplied instruction name, renders raw data via InstructionCard with defaultRaw.
app/features/transaction/ui/InstructionsSection.tsx Swaps MangoDetailsCard for CommonInstructionDetailsCard; getMangoInstructionLabel supplies the instruction name; guard against undefined transactionIx already present.
app/utils/programs.ts Adds the three Mango v3 program IDs to PROGRAM_INFO_BY_ID using Address-typed keys from the new package; each entry correctly scoped to its cluster.
app/features/transaction-history/model/use-resolved-instruction-summaries.ts Plugs resolveMangoInstructionName into the NAME_SOURCES chain alongside the existing Lighthouse and ZkElGamal resolvers; signatures are consistent.
app/components/account/TokenHistoryCard.tsx Import moved from removed local types to new package subpath; parseMangoInstructionTitle call remains inside try/catch, so the throw-on-unknown behavior is safely handled.
packages/decoder-mango/src/tests/detection.spec.ts Comprehensive unit tests: covers all 73 instruction names via table iteration, non-Mango program returns, empty/short data, unknown discriminator, and three getMangoInstructionLabel fallback labels.
packages/decoder-mango/package.json Correctly declares both @solana/kit and @solana/web3.js as peer deps (used by program-ids.ts and detection.ts respectively); @solana-program/token is a devDependency for tests only.
.github/workflows/ci.yaml Adds pnpm build:packages step before the sitemap generation script, which is required because update-sitemap.ts imports programs.ts which transitively imports the built @explorer/decoder-mango.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[TransactionInstruction] --> B{isMangoInstruction?}
    B -- No --> C[Other decoders / Unknown]
    B -- Yes --> D[getMangoInstructionLabel]
    D --> E{discriminator readable?}
    E -- 4+ bytes, known --> F["MANGO_INSTRUCTION_NAMES.get(discriminator)\ne.g. 'PlacePerpOrder'"]
    E -- empty data --> G["'No data'"]
    E -- unknown discriminator --> H["'Unknown'"]
    F --> I["CommonInstructionDetailsCard\ntitle: 'Mango v3 (deprecated): PlacePerpOrder'\ndefaultRaw=true"]
    G --> I
    H --> I
    I --> J[InstructionCard\nshows raw accounts + hex data]

    K[Transaction History Row] --> L{isMangoInstruction?}
    L -- Yes --> M[parseMangoInstructionTitle\nthrows on unknown → caught]
    L -- No --> N[Other resolvers]

    O[NAME_SOURCES chain\nuse-resolved-instruction-summaries] --> P[resolveMangoInstructionName\nprogramId + Uint8Array discriminator]
    P --> Q[string name or undefined]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[TransactionInstruction] --> B{isMangoInstruction?}
    B -- No --> C[Other decoders / Unknown]
    B -- Yes --> D[getMangoInstructionLabel]
    D --> E{discriminator readable?}
    E -- 4+ bytes, known --> F["MANGO_INSTRUCTION_NAMES.get(discriminator)\ne.g. 'PlacePerpOrder'"]
    E -- empty data --> G["'No data'"]
    E -- unknown discriminator --> H["'Unknown'"]
    F --> I["CommonInstructionDetailsCard\ntitle: 'Mango v3 (deprecated): PlacePerpOrder'\ndefaultRaw=true"]
    G --> I
    H --> I
    I --> J[InstructionCard\nshows raw accounts + hex data]

    K[Transaction History Row] --> L{isMangoInstruction?}
    L -- Yes --> M[parseMangoInstructionTitle\nthrows on unknown → caught]
    L -- No --> N[Other resolvers]

    O[NAME_SOURCES chain\nuse-resolved-instruction-summaries] --> P[resolveMangoInstructionName\nprogramId + Uint8Array discriminator]
    P --> Q[string name or undefined]
Loading

Reviews (13): Last reviewed commit: "chore: dedupe pnpm catalogs and drop sta..." | Re-trigger Greptile

Comment thread packages/decoder-mango/src/market.ts Outdated
Comment thread packages/decoder-mango/src/market.ts Outdated
@rogaldh rogaldh changed the title Feat/extract mango client feat(mango): extract mango client Jun 15, 2026
@rogaldh rogaldh requested a review from askov June 15, 2026 17:20
@rogaldh

rogaldh commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile-apps issues were addressed

Comment thread packages/decoder-mango/src/market.ts Outdated
@rogaldh rogaldh force-pushed the feat/extract-mango-client branch from 316cc76 to b649d04 Compare July 1, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant